package com.ss2;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Locale;

/**
 * @Auther: 520ljs
 * @Date: 2022/3/15 - 03 - 15 - 13:25
 */
public class Test08 {
    //这是一个main方法，是程序的入口
    public static void main(String[] args) {
        //1.完成实例化：
        //方法1：now()--->获取当前的日期，时间，日期+时间
        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);
        LocalTime localTime = LocalTime.now();
        System.out.println(localTime);
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);

        //方法2：of()--->设置指定的日期，时间，日期+时间
        LocalDate of = LocalDate.of(2010, 5, 6);
        System.out.println(of);
        LocalTime of1 = LocalTime.of(12,35,56);
        System.out.println(of1);
        LocalDateTime of2 = LocalDateTime.of(1890,12,23,13,24,15);
        System.out.println(of2);

        //LocalDate,LocalTime用的不如LocalDateTime多
        //线面讲解用LocalDateTime:
        //一些 常用的get方法
        System.out.println(localDateTime.getYear());//2022
        System.out.println(localDateTime.getMonth());//MARCH
        System.out.println(localDateTime.getMonthValue());//3
        System.out.println(localDateTime.getDayOfMonth());//15
        System.out.println(localDateTime.getDayOfWeek());//TUESDAY
        System.out.println(localDateTime.getHour());//13
        System.out.println(localDateTime.getMinute());//46
        System.out.println(localDateTime.getSecond());//31

        //不是set，叫with
        //体会:不可变性
        LocalDateTime localDateTime2 = localDateTime.withMonth(8);
        System.out.println(localDateTime);
        System.out.println(localDateTime2);

        //提供了加减的操作：
        //加：
        LocalDateTime localDateTime1 = localDateTime.plusMonths(4);
        System.out.println(localDateTime);
        System.out.println(localDateTime1);
        //减：
        LocalDateTime localDateTime3 = localDateTime.minusMonths(5);
        System.out.println(localDateTime);
        System.out.println(localDateTime3);
    }
}
